<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\AdminBaseController;
use App\Http\Requests\Admin\AdminUsersPayPasswordRequest;
use App\Http\Requests\Admin\AdminUsersRequest;
use App\Services\Admin\AdminUsersService;
use Illuminate\Http\Request;

class AdminUsersController extends AdminBaseController
{
    protected $services = null;

    public function __construct(AdminUsersService $Services)
    {
        parent::__construct();
        $this->services = $Services;
    }

    public function captcha()
    {
        return $this->success($this->services->captcha());
    }


    public function information(AdminUsersRequest $request)
    {
        if ($request->isMethod('post')) {
            $result = $this->services->modifyPassword();
            if ($result) {
                return $this->success();
            } else {
                return $this->failure($this->services->getError());
            }
        } else {
            $info = $this->services->getManageInfo();
            if (method_exists($info, 'toArray')) {
                $info = $info->toArray();
            }
            return $this->success($info);
        }
    }

    public function modifyPayPassword(AdminUsersPayPasswordRequest $request)
    {
        $result = $this->services->modifyPayPassword();
        if ($result) {
            return $this->success();
        } else {
            return $this->failure($this->services->getError());
        }
    }


    public function showinfo(Request $request)
    {
        return $this->success($this->services->getManageInfo());
    }

    public function power()
    {
        $result = $this->services->setPower();
        if ($result) {
            return $this->success();
        } else {
            return $this->failure($this->services->getError("Error"));
        }
    }

    public function routes()
    {
        $result = $this->services->setRoutes();
        if ($result) {
            return $this->success();
        } else {
            return $this->failure($this->services->getError("Error"));
        }

    }


    public function tempGroup()
    {

        $result = $this->services->tempGroup();
        if ($result) {
            return $this->success();
        } else {
            return $this->failure($this->services->getError("Error"));
        }
    }

    public function getGroupAllAdmin()
    {
        return $this->success($this->services->getGroupAllAdmin());
    }

    /**
     * 同步管理员到数据中心
     */
    public function SyncDataCenterUsers()
    {
        return $this->success($this->services->SyncDataCenterUsers());
    }
}
